<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<jsp:include page="../common/common.jsp">
	<jsp:param name="title" value="节点"/>
</jsp:include>

<div class="page-header">
	<h1>
		节点列表
	</h1>
</div>

<div class="row">
	<div class="col-xs-12">
		<div class="row">
			<div class="col-xs-12">
				<div>
					<div class="dataTables_wrapper form-inline no-footer">
						<table id="_table" class="table table-striped table-bordered table-hover dataTable no-footer">
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- page specific plugin scripts -->
<script type="text/javascript">
	$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
		jQuery(function($) {
			var nodeKey='${NODE_KEY}';
			var toolcon=[];
			if(nodeKey=="MASTER" || nodeKey == ""){
				toolcon=[
					{text : '新增', clazz : 'btn-info', icon : 'fa fa-plus-circle blue', permission : '/admin/nodeDB/edit', handler : function(){
						$.aceRedirect("${_path}/admin/nodeDB/edit");
					}},
					{text : '删除', clazz : 'btn-danger', icon : 'fa fa-trash-o red', permission : '/admin/nodeDB/delete/submit', handler : function(){
						$table.ajaxDelete({
							url : "${_path}/admin/nodeDB/delete/submit"
						});
					}}
				]
			}else{
				toolcon=[
					{text : '新增', clazz : 'btn-info', icon : 'fa fa-plus-circle blue', permission : '/admin/nodeDB/edit', handler : function(){
						$.aceRedirect("${_path}/admin/nodeDB/edit");
					}},
					{text : '删除', clazz : 'btn-danger', icon : 'fa fa-trash-o red', permission : '/admin/nodeDB/delete/submit', handler : function(){
						$table.ajaxDelete({
							url : "${_path}/admin/nodeDB/delete/submit"
						});
					}},
					{text : '返回默认节点', clazz : 'btn-purple', icon : 'fa fa-file-text-o purple', permission : '/admin/nodeDB/default', handler : function(){
						$.aceRedirect("${_path}/admin/nodeDB/default");
						var parm=parseInt(Math.random*10);
						window.location.href="${_path}/admin/admin?"+parm;
					}}
				]
			}
    		var $table = $("#_table").table({
    			//请求后台的URL（*）
    			url : "${_path}/admin/nodeDB/list",
    			//formId : "_form",
				tools : toolcon,
				//表格的列
				columns : [
			        {field:'id', hide : true},
			        {field:'name', title:'名称', align:'left'},
			        {field:'dbName', title:'节点数据库名称', mobileHide : true},
			        /* {field:'ip', title:'ip地址', mobileHide : true},
			        {field:'adminName', title:'管理员名称', align:'left'},
			        {field:'password', title:'管理员密码', mobileHide : true} */
				],
				operate : [
					{text : '修改', clazz : 'blue', icon : 'fa fa-pencil', permission : '/admin/nodeDB/edit', handler : function(d, i){
						$.aceRedirect("${_path}/admin/nodeDB/edit?id=" + d.id);
					}},
					{text : '删除', clazz : 'red', icon : 'fa fa-trash-o', permission : '/admin/nodeDB/delete/submit', handler : function(){
						$table.ajaxDelete({
							url : "${_path}/admin/nodeDB/delete/submit"
						});
					}},
					{text : '切换节点', clazz : 'green', icon : 'fa fa-cog', permission : '/admin/nodeDB/change', handler : function(){
							$.aceRedirect("${_path}/admin/nodeDB/change?id=" + $table.getSelectedItemKeys("id"));
							var parm=parseInt(Math.random*10);
							window.location.href="${_path}/admin/admin?"+parm;
					}}
				],
				after : function(){
					// 权限处理
					$.permission();
				}
			});
    		$("#_table > tbody >tr").each(function(){
    			obj=$(this).find("td").last().find(".action-buttons").find("a").last();
    			obj.append("切换节点");
    		});
			
			//搜索
			$(".search-data").keyup(function () { 
				$table.search();
			});
            
			// 取消
			$("#_cancel").click(function(){
				$table.search();
			});
		});
	});
</script>
